package patterns.observePattern;

public abstract class ServiceUser {
	public String name;
	public String phoneNumber;
	public Float useTime;
	public MobileServerData mobileServerData;
	public boolean accept;

	public void afterNotified() {
		if (getAccept() == true) {
			willDo();
		}
	}

	public void afterNotifiedOberved(ObservedMessage observedMessage) {
		if (getAccept() == true) {
			afterObservedwillDo(observedMessage);
		}

	}

	public abstract void afterObservedwillDo(ObservedMessage observedMessage);

	public abstract void willDo();

	public void deleteAcceptMessage() {
		try {
			mobileServerData.deleteUser(this);
			setAccept(false);
			this.mobileServerData = null;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public Float getUseTime() {
		return useTime;
	}

	public void setUseTime(Float useTime) {
		this.useTime = useTime;
	}

	public String userInfo() {
		return new StringBuffer("name:").append(name).append(",phoneNumber").append(phoneNumber).append(",useTime:")
				.append(useTime).toString();
	}

	public void setAccept(boolean accept) {
		this.accept = accept;
	}

	public boolean getAccept() {
		return this.accept;
	}

	public void addUserPassive(MobileServerData mobileServerData) throws Exception {
		if (this.mobileServerData == null) {
			this.mobileServerData = mobileServerData;
			setAccept(true);
		} else {
			throw new Exception("current watcher is bind to a observed server");
		}
	}
}
